const express = require('express');
const { graphqlHTTP } = require('express-graphql');
const loggingMiddleware = require('./middleware/loginCheck.js');
const cors = require('cors');
const app = express();
var GraphQLSchema = require('./schema/default.js');

// 处理跨域请求
app.use(cors());
// 处理请求
app.use(express.json());//express.json=bodyParser.json
app.use(express.urlencoded({ extended: true }));

// 使用登录中间件
// app.use(loggingMiddleware);


app.use('/graphql', graphqlHTTP((request) => (
  {
    schema: GraphQLSchema,
    graphiql: true,
    rootValue: request.headers,
    context: request.headers,
  }
)));

module.exports = app;